/* Copyright (c) 2004-2023 peigen.info. All rights reserved. */
package com.gitee.peigenlpy.actable.example.repository.entity;

import com.alibaba.fastjson2.annotation.JSONField;
import com.gitee.peigenlpy.actable.annotation.Column;
import com.gitee.peigenlpy.actable.annotation.IsNativeDefValue;
import com.gitee.peigenlpy.actable.constants.MySqlTypeConstant;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldDefaults;
import org.beetl.sql.annotation.entity.AutoID;

import javax.persistence.MappedSuperclass;
import java.util.Date;

/**
 * <b>(AbstractCreateTimeEntity)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/4/25
 */
@Getter
@Setter
@FieldDefaults(level = AccessLevel.PRIVATE)
@MappedSuperclass
public abstract class AbstractCreateTimeEntity implements CreateTimeEntityEnable {
    /** 数据库自增主键，用于日后数据迁移定位更精确 */
    @JSONField(ordinal = 0)
    @Column(name = "id", isKey = true, isNull = false, isAutoIncrement = true, comment = "id")
    @org.beetl.sql.annotation.entity.Column(value = "id")
    @AutoID
    Integer id;

    /** 创建时间，默认当前时间 */
    @Column(name = "create_time", type = MySqlTypeConstant.TIMESTAMP, defaultValue = "CURRENT_TIMESTAMP", comment = "创建时间")
    @IsNativeDefValue
    @org.beetl.sql.annotation.entity.Column(value = "create_time")
    Date createTime = new Date();

    /** 更新时间，默认当前时间 */
    @Column(name = "update_time", type = MySqlTypeConstant.TIMESTAMP, defaultValue = "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", comment = "更新时间")
    @IsNativeDefValue
    @org.beetl.sql.annotation.entity.Column(value = "update_time")
    Date updateTime = new Date();
}